<?php

class DefaultApp extends MallbaseApp {

    function index() {
        $this->assign('index', 1); // 标识当前页面是首页，用于设置导航状态
        $this->_config_seo(array(
            'title' => Lang::get('relationshipInfoindex') . ' - ' . Conf::get('site_title'),
        ));
        $this->assign('page_description', Conf::get('site_description'));
        $this->assign('page_keywords', Conf::get('site_keywords'));
        $this->display('index.html');
    }

    function ajaxorder() {
        $user_id = $this->visitor->get('user_id');
        //获取订单记录没有查看的IDS
        $order_log_mod = & m('orderlog');

        //用户作为买家的提示 
        $buyer_order_log = $order_log_mod->find(
                array(
                    'conditions' => "buyer_id = '$user_id' AND order_log_status = 0 AND operator_type='seller'",
                    'join' => 'belongs_to_order',
                )
        );
        //用户作为卖家的提示 
        $seller_order_log = $order_log_mod->find(
                array(
                    'conditions' => "seller_id = '$user_id' AND order_log_status = 0 AND operator_type='buyer' AND changed_status <> '".Lang::get('drawback')."' ",
                    'join' => 'belongs_to_order',
                )
        );
$buyer_refund_log=$order_log_mod->find(
                array(
                    'conditions' => "seller_id = '$user_id' AND order_log_status = 0 AND operator_type='buyer' AND changed_status = '".Lang::get('drawback')."'",
                    'join' => 'belongs_to_order',
                )
        );
        $order_log_array = array();

        $k = 0;
        if (!empty($buyer_order_log)) {
            foreach ($buyer_order_log as $key => $order_log) {
                $order_log_array['list'][$k]['title'] =  Lang::get('buyer_has_neworder') . $order_log['changed_status'] .Lang::get('order_number') . $order_log['order_sn'];
                $order_log_array['list'][$k]['url'] = 'index.php?app=buyer_order&act=view&order_id=' . $order_log['order_id'];
                $order_log_array['list'][$k]['notice'] = Lang::get('buyer_system_note');
                $order_log_array['list'][$k]['log_id'] = $order_log['log_id'];
                $k++;
            }
        }
        if (!empty($buyer_refund_log)) {
            $order_log_array['list'][$k]['title'] = Lang::get('seller_has_neworder').'<strong style="color:red">' . count($buyer_refund_log) . '</strong>'.Lang::get('not_processed_order');
            $order_log_array['list'][$k]['url'] = 'index.php?app=refund&act=receive';
            $order_log_array['list'][$k]['notice'] = Lang::get('buyer_system_note');
            $order_log_array['list'][$k]['log_id'] = 'all';
            $k++;
        }
        if (!empty($seller_order_log)) {
            $order_log_array['list'][$k]['title'] = Lang::get('seller_has_neworder').'<strong style="color:red">'. count($seller_order_log) . '</strong>'.Lang::get('not_processed_order');
            $order_log_array['list'][$k]['url'] = 'index.php?app=seller_order';
            $order_log_array['list'][$k]['notice'] =Lang::get('buyer_system_note');
            $order_log_array['list'][$k]['log_id'] = 'all';
        }

        $order_log_array['order_log_num'] = count($order_log_array['list']);

        $json_data = json_encode($order_log_array);
        echo $json_data;
        die;
    }

    function ajaxorderdrop() {
        $log_id = trim($_GET['log_id']);
        if (empty($log_id)) {
            return;
        }
        if ($log_id == 'all') {
            $order_log_mod = & m('orderlog');
            $user_id = $this->visitor->get('user_id');
            $seller_order_log = $order_log_mod->find(
                    array(
                        'conditions' => "seller_id = '$user_id' AND order_log_status = 0 AND operator_type='buyer'",
                        'join' => 'belongs_to_order',
                    )
            );
            if (!empty($seller_order_log)) {
                foreach ($seller_order_log as $key => $order) {
                    $data['order_log_status'] = 1;
                    $order_log_mod->edit($key, $data);
                }
            }
            $json_data = json_encode(array('done' => 'true'));
            echo $json_data;
            die;
        }

        $order_log_mod = & m('orderlog');
        $data['order_log_status'] = 1;
        $edit_rows = $order_log_mod->edit($log_id, $data);
        if ($edit_rows) {
            $json_data = json_encode(array('done' => 'true'));
        } else {
            $json_data = json_encode(array('done' => 'false'));
        }
        echo $json_data;
        die;
    }
    function version(){
        echo Lang::get('version_nm').': 160328'.'<br/>'.Lang::get('order_sn').':1554546';
    }
}
?>